package edu.towson.cosc490.incaseofemergency.objects;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class SupplyKitItem {
	private String itemName;
	private int suggestedQuantity;
	private int ownedQuantity;
	private boolean perishable;
	private Date expirationDate;
	private int kitType;
	
	//Expiration date is sent by string in constructors in MM/dd/yyyy format
	//The KitItemData object handles conversion to Date object
	public SupplyKitItem(String itemName, int suggestedQuantity, boolean perishable, String expirationDate, int kitType){
		this.itemName= itemName;
		this.suggestedQuantity = suggestedQuantity;
		this.perishable = perishable;
		this.ownedQuantity = 0;
		this.kitType = kitType;
		
		if(perishable){
			try{
				this.expirationDate = new SimpleDateFormat("MM/dd/yyy", Locale.US).parse(expirationDate);
			}
			catch(ParseException e){
				System.out.println("Parse excepion: " + e.getLocalizedMessage());
				this.expirationDate = new Date(System.currentTimeMillis());
			}
		} else{
			this.expirationDate = null;
		}
	}
	
	public void setOwnedQuantity(int ownedQuantity){
		this.ownedQuantity = ownedQuantity;
	}
	
	public void setPerishable(boolean perishable, String expirationDate){
		this.perishable = perishable;
		if(perishable){
			try{
				this.expirationDate = new SimpleDateFormat("MM/dd/yyy", Locale.US).parse(expirationDate);
			}
			catch(ParseException e){
				System.out.println("Parse excepion: " + e.getLocalizedMessage());
			}
		} else{
			this.expirationDate = null;
		}
	}
	
	public String getItemName(){
		return this.itemName;
	}
	
	public String getSuggestedQuantity(){
		String quantity = new String("" + suggestedQuantity );
		return quantity;
	}
	
	public String getOwnedQuantity(){
		String quantity = new String("" + ownedQuantity );
		return quantity;
	}

	public boolean isPerishable(){
		return this.perishable;
	}
	public String perishableString(){
		String perish = new String();
		if(perishable){
			perish = "true";
		} else{
			perish = "false";
		}
		return perish;
	}
	
	public String getExpirationDate(){
		if(perishable){
			SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
			String date = dateFormat.format(expirationDate);
			return date;
		} else{
			return "No Expiration";
		}
	}
	
	public int getKitType(){
		return this.kitType;
	}
	
	public void setKitType(int type){
		this.kitType = type;
	}
}

